﻿import QtQuick 2.0

Item {
    function second2Time(second){

        if(second < 0){
            return "00:00:00"
        }

        let hh = Math.floor(second / 3600)
        let mm = Math.floor((second % 3600) / 60)
        let ss = Math.floor(second % 60)

        return (hh>9?"":"0") + hh + ":" +
               (mm>9?"":"0")+ mm + ":" +
               (ss>9?"":"0") + ss
    }

    function justifyAlignAppendSpace(title, titleWidth, textWidth, spaceWidth){


        // 补空格用的数量计算
        let lackWidth = titleWidth - textWidth - 5*dp
        let spaceNum = Math.round(lackWidth / spaceWidth)
        let spaceBetweenNum = Math.round(spaceNum / (title.length-1))
        let spaceSideNum = Math.round((spaceNum - spaceBetweenNum*(title.length-1))/2)
//        console.log("标题", lackWidth, titleWidth, titleWidth, spaceWidth, title, spaceNum, spaceBetweenNum, spaceSideNum)
        let rr = ""
        // 前面补的空格
        for(let i = 0; i < spaceSideNum; i ++){
            rr = rr + " "
        }
        // 中间的文字
        for(let i = 0; i < title.length; i ++){
            rr = rr + title[i]
            if(i !== title.length - 1){
                for(let j = 0; j < spaceBetweenNum; j ++){
                    rr = rr + " "
                }
            }
        }
        // 末尾补的空格
        for(let i = 0; i < spaceSideNum; i ++){
            rr = rr + " "
        }
        return rr

    }
}
